package fileAndIO;

import org.junit.Test;

import java.io.*;

// 数据流
public class Test6 {
    @Test
    public void test1() throws IOException {
        // 写入
        DataOutputStream dataOutputStream = new DataOutputStream(new FileOutputStream("C:\\Users\\83726\\ccc\\aaa.dat"));
        dataOutputStream.writeDouble(3.14);
        dataOutputStream.writeChar('Q');
        dataOutputStream.writeInt(50);
        dataOutputStream.writeUTF("牛子哥");
        dataOutputStream.flush();
        dataOutputStream.close();
    }

    @Test
    public void test2() throws IOException {
        // 读取
        DataInputStream dataInputStream = new DataInputStream(new FileInputStream("C:\\Users\\83726\\ccc\\aaa.dat"));
        double readDouble = dataInputStream.readDouble();
        char readChar = dataInputStream.readChar();
        int readInt = dataInputStream.readInt();
        String readUTF = dataInputStream.readUTF();
        System.out.println(readDouble);
        System.out.println(readChar);
        System.out.println(readInt);
        System.out.println(readUTF);
        dataInputStream.close();
    }
}
